package com.isnmp.common.snmp.impl;

import net.percederberg.mibble.MibValueSymbol;
import net.percederberg.mibble.snmp.SnmpObjectType;

import org.snmp4j.PDU;
import org.snmp4j.Snmp;
import org.snmp4j.Target;
import org.snmp4j.event.ResponseEvent;
import org.snmp4j.smi.OID;
import org.snmp4j.smi.Variable;
import org.snmp4j.smi.VariableBinding;

import com.isnmp.common.base.MyException;
import com.isnmp.common.snmp.SNMPAPI;

public class SetOIDValueAction {
    public static void setValue(String paramString1, String paramString2, String paramString3, Snmp paramSnmp, Target paramTarget) throws MyException {
        try {
            MibValueSymbol localMibValueSymbol = SNMPAPIImpl.getInstance().getMibSymbolByOid(paramString1);
            SnmpObjectType localObject = (SnmpObjectType) localMibValueSymbol.getType();
            Variable localVariable1 = SNMPUtils.getVariable(((SnmpObjectType) localObject).getSyntax(), paramString3);
            PDU localPDU1 = new PDU();
            localPDU1.add(new VariableBinding(new OID(paramString1 + "." + paramString2), localVariable1));
            ResponseEvent localResponseEvent = paramSnmp.set(localPDU1, paramTarget);
            SNMPUtils.checkSNMPErro(localResponseEvent);
            PDU localPDU2 = localResponseEvent.getResponse();
            VariableBinding localVariableBinding = localPDU2.get(0);
            Variable localVariable2 = localVariableBinding.getVariable();
            String str = localVariable2.toString();
            if ((str.equalsIgnoreCase("noSuchInstance")) || (str.equalsIgnoreCase("No such name")) || (str.equalsIgnoreCase("noSuchObject")))
                throw new MyException(SNMPAPI.MessageNoSuchOID);
        } catch (Exception localException) {
            Object localObject = Messages.getString("SetOIDValueAction.0") + paramString1 + Messages.getString("SetOIDValueAction.1") + localException.getMessage();
            throw new MyException((String) localObject);
        }
    }

    static void setValue(String paramString, Variable paramVariable, Snmp paramSnmp, Target paramTarget) throws MyException {
        try {
            PDU localPDU = new PDU();
            localPDU.add(new VariableBinding(new OID(paramString), paramVariable));
            Object localObject = paramSnmp.set(localPDU, paramTarget);
            SNMPUtils.checkSNMPErro((ResponseEvent) localObject);
        } catch (Exception localException) {
            Object localObject = Messages.getString("SetOIDValueAction.0") + paramString + Messages.getString("SetOIDValueAction.1") + localException.getMessage();
            throw new MyException((String) localObject);
        }
    }
}